<template>
 <div class="User">
   <el-menu
       mode="horizontal"
       background-color="#545c64"
       text-color="#fff">
     <el-menu-item v-for="(item,index) in navmenu" :key="index" @click="go(item.href)"> {{item.content}}</el-menu-item>
     <el-menu-item @click="unlogin()"style="position: fixed;right: 19px;top: 8px">注销</el-menu-item>
   </el-menu>
   <br><br>
   <el-descriptions title="用户信息" :column="3" border ></el-descriptions>
   <br>
     <el-table :data="data" stripe border style="width: 100%" v-if="ID===1">
       <el-table-column prop="nickname" label="姓名"></el-table-column>
       <el-table-column prop="id" label="学号"></el-table-column>
       <el-table-column prop="sex" label="性别"></el-table-column>
       <el-table-column prop="age" label="年龄"></el-table-column>
     </el-table>
   <el-table :data="data" stripe border style="width: 100%" v-if="ID===2">
     <el-table-column prop="nickname" label="姓名"></el-table-column>
     <el-table-column prop="identity" label="身份"></el-table-column>
     <el-table-column prop="sex" label="性别"></el-table-column>
     <el-table-column prop="age" label="年龄"></el-table-column>
     <el-table-column prop="address" label="地址"></el-table-column>
   </el-table>

   <el-table :data="data" stripe border style="width: 100%" v-if="ID===0">
        <el-table-column prop="nickname" label="姓名"></el-table-column>
        <el-table-column prop="id" label="管理员ID"></el-table-column>
        <el-table-column prop="sex" label="性别"></el-table-column>
        <el-table-column prop="age" label="年龄"></el-table-column>
      </el-table>
  </div>
</template>

<script>
export default {
  created() {
    axios.get('/role/index',{withCredentials:true}).then(res=>{
      console.log(res);
      if(res.data.code===10000){
        this.navmenu=res.data.data;
      }else {
        this.$router.push('/login');
        this.$message.error(res.data.msg);
      }
    }),
    axios.get("/member/findMemberByUserId",{withCredentials:true}).then(res=>{
      console.log(res);
      if(res.data.code===10000){
        this.data=res.data.data;
      }else {
        this.$router.push('/login');
        this.$message.error(res.data.msg);
      }
      if (this.data[0].id===2){
        this.ID=this.data[0].id
      }else if (this.data[0].id===1){
        this.ID=this.data[0].id
      }else if (this.data[0].id===0){
        this.ID=this.data[0].id
      }
    })
  },
  data(){
    return{
      ID:'',
      data:[],
      navmenu:[]
    }
  },
  methods:{
    go(index){
      this.$router.push(index);
    },
    unlogin(){
      axios.post('/user/logout').then(res=> {
        if(res.data.code===10000){
          this.$message.success(res.data.msg);
          this.$router.push('/login');
        }else{
          this.$message.error(res.data.msg);
        }
      })
    }
  }

}
</script>

<style scoped>

</style>